﻿

namespace Jinndev {

    public class EventData {

        public string type;
        public object[] args;

        public EventData(string type) {
            this.type = type;
        }

        public EventData(string type, params object[] args) {
            this.type = type;
            this.args = args;
        }

        public object FirstArg {
            get {
                return (args == null || args.Length == 0) ? null : args[0];
            }
        }

        public object this[int index] {
            get {
                if (args != null && index < args.Length) {
                    return args[index];
                }
                return null;
            }
        }

        /// <summary>
        /// 得到指定值
        /// </summary>
        public T GetArg<T>(int index) {
            if (args != null && index < args.Length) {
                object obj = args[index];
                return obj is T ? (T)obj : default;
            }
            return default;
        }

        /// <summary>
        /// 得到第一个值
        /// </summary>
        public T GetFirstArg<T>() {
            return GetArg<T>(0);
        }

    }

}
